package top.fzqblog.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;

import butterknife.BindView;
import butterknife.ButterKnife;
import top.fzqblog.firstapp.R;
import top.fzqblog.model.Meizi;

/**
 * Created by 抽离 on 2017/9/25 0025.
 */

public class GlideAdapter extends RecyclerView.Adapter<ImageViewHolder> {

    private Context context;

    private Meizi meizi;

    public GlideAdapter(Context context, Meizi meizi) {
        this.context = context;
        this.meizi = meizi;
    }

    @Override
    public ImageViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view =  LayoutInflater.from(context).inflate(R.layout.retrofit_glide, parent, false);
        ImageViewHolder imageViewHolder = new ImageViewHolder(view);
        return imageViewHolder;
    }

    @Override
    public void onBindViewHolder(ImageViewHolder holder, int position) {
        Log.i("tag", position+"");
        Glide.with(context)
                .load(meizi.getResults().get(position).getUrl())
                .fitCenter()
                .animate(R.anim.fadein)
                .placeholder(R.color.colorAccent)
                .into(holder.imageView);
    }

    @Override
    public int getItemCount() {
        return meizi.getResults().size();
    }
}


class ImageViewHolder extends RecyclerView.ViewHolder{

    @BindView(R.id.retrofitGlideIV)
    public ImageView imageView;


    public ImageViewHolder(View itemView) {
        super(itemView);
        ButterKnife.bind(this, itemView);
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

            }
        });
    }
}